package org.yzh.protocol.body;

import io.netty.buffer.ByteBuf;

/**
 * @author yezhihao
 * @home https://gitee.com/yezhihao/jt808-server
 */
public class Location {
    public static final int id = 0x01;

    public static int id() {
        return id;
    }

    private int statusBit;
    private int longitude;
    private int latitude;

    public int getStatusBit() {
        return statusBit;
    }

    public void setStatusBit(int statusBit) {
        this.statusBit = statusBit;
    }

    public int getLongitude() {
        return longitude;
    }

    public void setLongitude(int longitude) {
        this.longitude = longitude;
    }

    public int getLatitude() {
        return latitude;
    }

    public void setLatitude(int latitude) {
        this.latitude = latitude;
    }


    public static class Schema implements io.github.yezhihao.protostar.Schema<Location> {

        public static final Location.Schema INSTANCE = new Location.Schema();

        private Schema() {
        }

        @Override
        public Location readFrom(ByteBuf input) {
            Location message = new Location();
            message.statusBit = input.readUnsignedByte();
            message.longitude = input.readInt();
            message.latitude = input.readInt();
            return message;
        }

        @Override
        public void writeTo(ByteBuf output, Location message) {
            output.writeByte(message.statusBit);
            output.writeInt(message.longitude);
            output.writeInt(message.latitude);
        }
    }
}